﻿@using KL.Store.Core
@{
    Layout = null;
    bool hasFacebookLogin = !string.IsNullOrEmpty(Parameters.FaceBookAppId);
    bool hasTwitterLogin = !string.IsNullOrEmpty(Parameters.TwitterAppId);
}
<div class="account-block-outer loginformouter">
    <div class="account-block-inner loginforminner">
        <h2>Facebook İle Bağlanın</h2>
        <h3>Facebook Kullanıcıları</h3>
        @if (hasFacebookLogin)
        {
            <script type="text/javascript">
                window.fbAsyncInit = function () {
                    FB.init({
                        appId: '@(Parameters.FaceBookAppId)',
                        status: true,
                        cookie: true,
                        xfbml: true,
                        oauth: true
                    });

                    function lgupdateButton(response) {
                        var lgbutton = document.getElementById('BtnFBLoginOnPage');
                        lgbutton.onclick = function () {
                            FB.login(function (response) {
                                if (response.authResponse) {
                                    FB.api('/me', function (response) {
                                        var userID = FB.getAuthResponse()['userID'];
                                        var accessToken = FB.getAuthResponse()['accessToken'];
                                        var signedRequest = FB.getAuthResponse()['signedRequest'];
                                        if (accessToken != "") {
                                            window.location = "@(Url.Action("FacebookLogin", "OAuth"))?token=" + accessToken;
                                        }
                                    });
                                } else {

                                }
                            }, { scope: 'email' });

                            return false;
                        }
                    }
                    FB.getLoginStatus(lgupdateButton);
                    FB.Event.subscribe('auth.statusChange', lgupdateButton);
                };
            </script>
            <a href="#" id="BtnFBLoginOnPage">
                <img id="fb-ile-baglan" src="/Images/@(Parameters.Theme)/facebook-ile-baglan-buyuk.png" alt="FB" /></a>
        }
    </div>
</div>
